﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Universities;

namespace UniversityTests
{
    [TestClass]
    public class CourseTest
    {
        [TestMethod]
        public void CourseConstructorTest()
        {
            Course target = new Course();
        }

        [TestMethod]
        public void AddTest()
        {
            Course target = new Course();
            Student student = new Student("Marin", 61131);
            target.Add(student);
            Assert.IsTrue(target.Contains(student));
            Assert.IsTrue(target.Contains(student.Fn));
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void AddDuplicateStudentTest()
        {
            Course target = new Course();
            Student student = new Student("Marin", 61131);
            target.Add(student);
            target.Add(student);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void AddStudentInFullCourseTest()
        {
            Course target = new Course();
            Student student = new Student("Marin", 61131);
            for (int i = 1; i <= 30; i++)
            {
                target.Add(new Student(student.Name, student.Fn + i));
            }
            target.Add(student);
        }

        [TestMethod]
        public void ContainsByFNTrueTest()
        {
            Course target = new Course();
            Student student = new Student("Marin", 61131);
            target.Add(student);
            int fn = 61131;
            bool expected = true;
            bool actual = target.Contains(fn);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ContainsByFNFalseTest()
        {
            Course target = new Course();
            int fn = 61131;
            bool expected = false;
            bool actual = target.Contains(fn);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ContainsStudentTrueTest()
        {
            Course target = new Course();
            Student student = new Student("Marin", 61131);
            target.Add(student);
            bool expected = true;
            bool actual = target.Contains(student);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ContainsStudentFalseTest()
        {
            Course target = new Course();
            Student student = new Student("Marin", 61131);
            bool expected = false;
            bool actual = target.Contains(student);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void RemoveByFNTest()
        {
            Course target = new Course();
            Student student = new Student("Marin", 61131);
            target.Add(student);
            int fn = 61131;
            target.Remove(fn);
            bool expected = false;
            bool actual = target.Contains(fn);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void RemoveStudentTest()
        {
            Course target = new Course();
            Student student = new Student("Marin", 61131);
            target.Add(student);
            target.Remove(student);
            bool expected = false;
            bool actual = target.Contains(student);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void RemoveNonExistingStudentTest()
        {
            Course target = new Course();
            Student student = new Student("Marin", 61131);
            target.Remove(student);
        }
    }
}
